package com.whw.springboot.walk.service.servicelmpl;

import com.whw.springboot.walk.entity.*;
import com.whw.springboot.walk.mapper.*;
import com.whw.springboot.walk.service.ActionService;
import com.whw.springboot.walk.service.RebackService;
import com.whw.springboot.walk.utils.ActionUtil;
import com.whw.springboot.walk.utils.ApplyUtil;
import com.whw.springboot.walk.utils.RebackUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class RebackServiceImpl implements RebackService {

    @Resource
    private RebackMapper rebackMapper;
    @Resource
    private RebackInfoMapper rebackInfoMapper;

    @Override
    public Message<String> insert(Reback reback) {
        String rebackId = "RE"+ RebackUtil.genRebackId();
        reback.setRebackId(rebackId);
        reback.setRebackUpdateTime(new Date());
        return rebackMapper.insert(reback) > 0 ? Message.success(null).add(rebackId) : Message.fail(null).add(null);
    }

    @Override
    public Message<?> deleteByPrimaryKey(String rebackId) {
        return rebackMapper.deleteByPrimaryKey(rebackId)> 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> updateByPrimaryKey(Reback reback) {
        return rebackMapper.updateByPrimaryKey(reback)> 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<Reback> findByPrimaryKey(String rebackId) {
        return Message.success(null).add(rebackMapper.findByPrimaryKey(rebackId));
    }

    @Override
    public Message<List<Reback>> findAll() {
        return Message.success(null).add(rebackMapper.findAll());
    }

    @Override
    public Message<List<Reback>> findRebackAndRebackInfo(String rebackId) {
        return Message.success(null).add(rebackMapper.findRebackAndRebackInfo(rebackId));
    }


}
